home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / SOURCE.BIN / Context.java < prev    next >
Encoding:
Java Source  |  1997-06-19  |  1.6 KB  |  81 lines

  1. package symantec.itools.lang;
  2.  
  3.  
  4. import java.applet.Applet;
  5. import java.net.URL;
  6.  
  7.  
  8. public class Context
  9. {
  10.     private static Applet applet;
  11.     private static URL documentBase;
  12.     private static boolean initialized = false;
  13.  
  14.     public static boolean isApplet()
  15.     {
  16.         return applet != null;
  17.     }
  18.  
  19.     public static boolean isApplication()
  20.     {
  21.         return applet == null;
  22.     }
  23.  
  24.     public static void setApplet(Applet a)
  25.     {
  26.         applet = a;
  27.         initialized = true;
  28.     }
  29.  
  30.     public static Applet getApplet()
  31.     {
  32.         return applet;
  33.     }
  34.  
  35.     public static void setDocumentBase(URL db)
  36.     {
  37.         documentBase = db;
  38.         initialized = true;
  39.     }
  40.  
  41.     private static void initializeApp()
  42.     {
  43.         StringBuffer p = new StringBuffer(System.getProperty("user.dir"));
  44.         int         pl = p.length();
  45.  
  46.         // If the system file separator isn't the URL file separator convert it.
  47.         try
  48.         {
  49.             char ps = (System.getProperty("file.separator")).charAt(0);
  50.             if(ps != '/')
  51.                 for(int counter = 0; counter < pl; counter++)
  52.                 {
  53.                     if(ps == p.charAt(counter)) p.setCharAt(counter, '/');
  54.                 }
  55.         } catch(StringIndexOutOfBoundsException e) {}
  56.  
  57.         try {
  58.             documentBase = new URL("file://" + p + "/");
  59.         } catch (java.net.MalformedURLException e) {
  60.         }
  61.     }
  62.  
  63.     public static URL getDocumentBase()
  64.     {
  65.         if (! initialized) {
  66.             initializeApp();
  67.             initialized = true;
  68.         }
  69.  
  70.         if(documentBase != null)
  71.         {
  72.             return documentBase;
  73.         }
  74.         else if (applet != null)
  75.         {
  76.             return applet.getDocumentBase();
  77.         }
  78.  
  79.         return null;
  80.     }
  81. }